package com.sqx.modules.goods.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.goods.service.GoodsService;
import com.sqx.modules.shop.service.SearchHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags={"用户端-商品"})
@RestController
@RequestMapping("/app/goods")
public class AppGoodsController {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private SearchHistoryService searchHistoryService;

    @ApiOperation("查看附近的店铺")
    @PostMapping(value = "selectShortShop")
    public Result selectShortShop(double lng, double lat, String shopName, Integer page, Integer limit, Long shopId){

        return goodsService.selectShortShop(lng, lat, shopName, page, limit, shopId);
    }

    @ApiOperation("根据商铺id查看商品列表")
    @GetMapping(value = "/selectGoodsList")
    public Result selectGoodsList(Long shopId, Double lng, Double lat){

        return goodsService.selectGoodsList(shopId, lng, lat);
    }

    @ApiOperation("查看商品详情")
    @GetMapping(value = "/selectGoodsById")
    public Result selectGoodsById(Long goodsId){

        return goodsService.selectGoodsById(goodsId);
    }

    /*@Login
    @ApiOperation("获取该商品规格名")
    @GetMapping(value = "selectSkuByGoodsId")
    public Result selectSkuByGoodsId(Long goodsId){
        //goodsService.selectSkuByGoodsId(goodsId)
        return null;
    }

    @Login
    @ApiOperation("获取该商品详细规格")
    @GetMapping(value = "selectAttrByGoodsId")
    public Result selectAttrByGoodsId(Long goodsId){
        //goodsService.selectAttrByGoodsId(goodsId);
        return null;
    }*/

    @ApiOperation("条件筛选店铺")
    @GetMapping(value = "selectShop")
    public Result selectShop(Long userId, Integer page, Integer limit, Integer screen, Integer shopTypeId, Double lng, Double lat, String impotr){
        if(impotr!=null&&!"".equals(impotr)){
            //添加历史搜索记录
            searchHistoryService.insertSearchHistory(userId, impotr);
        }
        //screen ==1 综合排序(评分)， == 2 商户类型筛选， == 3 距离排序，  ==4 销量,  ==5 配送费排序， ==6 免配送费筛选
        //排序：评分，销量，距离，配送费最低，起送价最低。。。。。
        //筛选：免配送费，
        return goodsService.selectShop(page, limit, screen, shopTypeId, lng, lat, impotr);
    }


    /*@ApiOperation("搜索（商铺名和商铺标签）")
    @GetMapping(value = "selectSearch")
    public Result selectSearch(@RequestAttribute Long userId, Integer page, Integer limit, String impotr, Double lng, Double lat){
        //添加历史搜索记录
        searchHistoryService.insertSearchHistory(userId, impotr);
        return goodsService.selectSearch(page, limit, impotr, lng, lat);
    }*/

    @ApiOperation("查看商铺评价")
    @GetMapping(value = "selectEvaluateByShopId")
    public Result selectEvaluateByShopId(Integer page, Integer limit, Long shopId, Integer grade){

        return goodsService.selectEvaluate(page, limit, shopId, grade);
    }

    @ApiOperation("查看商品评价")
    @GetMapping(value = "selectEvaluateByGoodsId")
    public Result selectEvaluateByGoodsId(Long goodsId, Integer page, Integer limit){

        return goodsService.selectEvaluateByGoodsId(goodsId, page, limit);
    }

}
